﻿using Maps.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace Maps.Drivers
{
    public class MapPartDriver : ContentPartDriver<MapPart> 
    {
        protected override DriverResult Display(MapPart part, string displayType, dynamic shapeHelper)
        {
            if (displayType == "Summary")
            {
                return ContentShape("Parts_Map_Summary", 
                    () => shapeHelper.Parts_Map_Summary(Place: part.Place));
            }

            return ContentShape("Parts_Map", 
                () => shapeHelper.Parts_Map(Place: part.Place));
        }

        //GET
        protected override DriverResult Editor(MapPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Map_Edit", 
                () => shapeHelper.EditorTemplate(TemplateName: "Parts/Map", Model: part));
        }

        //POST
        protected override DriverResult Editor(MapPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}
